Skip to main content

Introduction

An index mapping is a hierarchical JSON document, consisting of one or more levels. Each level defines a properties setting, which is a dictionary of all the fields on that level and their mapping.

A simple example of an index mapping, consider the following object, and its mapping:

Object:

{    "status": "Active"}

Mapping:

{  "index-name": {    "mappings": {      "properties": {        "status": {          "type": "keyword"        }      }    }  }}

There is one level in the object, and the field "status" is the key in the properties dictionary in the root level.

A field has a type, and zero or more parameters. The parameters are generally only of interest to OpenSearch, to know how to handle the field, but there are a few notable exceptions:

  • meta
  • fields

meta#

The parameter meta contains meta data that is relevant for the application using this index. The AIH-Search is using the meta parameter for determining the display name of the field.
Ex., a field in a JSON object is called "failureMode", but it should be displayed as "Failure Mode", the mapping would look like this:

{  "index-name": {    "mappings": {      "properties": {        "failureMode": {          "type": "keyword",          "meta": {            "display_name": "Failure Mode"          }        }      }    }  }}

fields#

The parameter fields enables multi-fields, which is used for indexing the same field with different data types. For instance, a string field could be mapped as a text field for full-text search, and as a keyword field for sorting or aggregations.

Ex. The field "Name" needs to be indexed both as a text field and a keyword field. The mapping would look like this

{  "index-name": {    "mappings": {      "properties": {        "name": {          "type": "keyword",          "fields": {            "nameAsText": {              "type": "text"            }          }        }      }    }  }}

Note how the fields object is structured in the same way as the properties object, i.e. it is a dictionary of fields with their mapping as a value. If you wish to query the field as text the full path needs to be provided, ex.:

{    "query": {        "match_phrase": {            "name.nameAsText": {                "query": "mads"            }        }    }}

Type: Object#

Two different kinds of child objects are indexed. A one-to-many relationship (ex., a list of Observations on one Deviation) are indexed with the type "nested" (Documented here).

The other type is a one-to-one and many-to-one relationship (ex., Equipment linked to Deviation), which is indexed as type "Object" (Documented here). If a field has the type "Object" it is omitted from the returned mapping. Ex., an object of the following structure would return this mapping:

Object:

{    "department": {        "code": "AST"    }}

Mapping:

{  "index-name": {    "mappings": {      "properties": {        "department": {          "properties": {            "code": {              "type": "keyword"            }          }        }      }    }  }}